package com.zf.apartment.controller;

import com.zf.apartment.domain.FlatsRoom;
import com.zf.apartment.domain.Room;
import com.zf.apartment.service.IFlatsRoomService;
import com.zf.common.annotation.Log;
import com.zf.common.core.controller.BaseController;
import com.zf.common.core.domain.AjaxResult;
import com.zf.common.core.page.TableDataInfo;
import com.zf.common.enums.BusinessType;
import com.zf.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公寓和房间关系Controller
 * 
 * @author ruoyi
 * @date 2024-10-13
 */
@RestController
@RequestMapping("/system/flatsroom")
public class FlatsRoomController extends BaseController
{
    @Autowired
    private IFlatsRoomService flatsRoomService;


    /**
     * 查询公寓和房间关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FlatsRoom flatsRoom)
    {
        startPage();
        List<FlatsRoom> list = flatsRoomService.selectFlatsRoomList(flatsRoom);
        return getDataTable(list);
    }

    /**
     * 根据公寓ID查询房间列表
     */
    @GetMapping("/listroom")
    public TableDataInfo listRoom(Long flatsId)
    {
        startPage();
        List<Room> list = flatsRoomService.selectRoomList(flatsId);
        return getDataTable(list);
    }

    /**
     * 导出公寓和房间关系列表
     */
    @Log(title = "公寓和房间关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlatsRoom flatsRoom)
    {
        List<FlatsRoom> list = flatsRoomService.selectFlatsRoomList(flatsRoom);
        ExcelUtil<FlatsRoom> util = new ExcelUtil<FlatsRoom>(FlatsRoom.class);
        util.exportExcel(response, list, "公寓和房间关系数据");
    }

    /**
     * 获取公寓和房间关系详细信息
     */
    @GetMapping(value = "/{flatsId}")
    public AjaxResult getInfo(@PathVariable("flatsId") Long flatsId)
    {
        return success(flatsRoomService.selectFlatsRoomByFlatsId(flatsId));
    }

    /**
     * 新增公寓和房间关系
     */
    @Log(title = "公寓和房间关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlatsRoom flatsRoom)
    {
        return toAjax(flatsRoomService.insertFlatsRoom(flatsRoom));
    }

    /**
     * 修改公寓和房间关系
     */
    @Log(title = "公寓和房间关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlatsRoom flatsRoom)
    {
        return toAjax(flatsRoomService.updateFlatsRoom(flatsRoom));
    }

    /**
     * 删除公寓和房间关系
     */
    @Log(title = "公寓和房间关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flatsIds}")
    public AjaxResult remove(@PathVariable Long[] flatsIds)
    {
        return toAjax(flatsRoomService.deleteFlatsRoomByFlatsIds(flatsIds));
    }
}
